//
//  LYLSearchMusicCell.m
//  ONE
//
//  Created by dllo on 16/6/7.
//  Copyright © 2016年 GroupNine. All rights reserved.
//

#import "LYLSearchMusicCell.h"
#import <UIImageView+WebCache.h>

@interface LYLSearchMusicCell ()

/** 专辑图片 */
@property (strong, nonatomic) UIImageView *albumView;
/** 背景图片 */
@property (strong, nonatomic) UIImageView *coverView;
/** 音乐名称 */
@property (strong, nonatomic) UILabel *musicNameLabel;
/** 作者名称 */
@property (strong, nonatomic) UILabel *authorNameLabel;

@end

@implementation LYLSearchMusicCell

+ (CGFloat)cellHeight {
    return 72;
}

#pragma mark - View Lifecycle

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        _albumView = [UIImageView new];
        _albumView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_albumView];
        [_albumView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.equalTo(@48);
            make.centerY.equalTo(self.contentView).offset(-2);
            make.left.equalTo(self.contentView).offset(12);
        }];
        
        _musicNameLabel = [UILabel new];
        _musicNameLabel.textColor = [UIColor colorWithWhite:72 / 255.0 alpha:1];// #484848
        _musicNameLabel.font = FontWithSize(16);
        [self.contentView addSubview:_musicNameLabel];
        [_musicNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_albumView).offset(3);
            make.left.equalTo(_albumView.mas_right).offset(6);
        }];
        
        _authorNameLabel = [UILabel new];
        _authorNameLabel.textColor = LYLAppThemeColor;
        _authorNameLabel.font = FontWithSize(12);
        [self.contentView addSubview:_authorNameLabel];
        [_authorNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_musicNameLabel.mas_bottom).offset(5);
            make.left.right.equalTo(_musicNameLabel);
        }];
        
        _coverView = [UIImageView new];
        _coverView.image = [UIImage imageNamed:@"music_cover_light"];
        _coverView.contentMode = UIViewContentModeCenter;
        _coverView.opaque = YES;
        [self.contentView addSubview:_coverView];
        [_coverView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.sizeOffset(CGSizeMake(62, 56));
            make.centerY.equalTo(self.contentView);
            make.left.equalTo(self.contentView).offset(6);
        }];
    }
    
    return self;
}

//- (void)prepareForReuse {
//    [super prepareForReuse];
//    _albumView.image = nil;
//}

- (void)setModel:(LYLMusicItemModel *)model
{
    if (_model != model) {
        _model = model;
        [_albumView sd_setImageWithURL:[NSURL URLWithString:model.cover] placeholderImage:[UIImage imageNamed:@"center_cd_cover"] options:SDWebImageRetryFailed];
        _musicNameLabel.text = model.title;
        _authorNameLabel.text = model.authorModel.desc;
    }
}


@end
